<template>
  <el-dialog
    title="抵押权人批量导入"
    :close-on-click-modal="false"
    @close="closeHandle"
    :visible.sync="visible">
    <el-upload
      drag
      :action="url"
      ref="upload"
      :before-upload="beforeUploadHandle"
      :on-success="successHandle"
      :show-file-list="false"
      :limit="1"
      :file-list="fileList"
      style="text-align: center;">

      <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
      <div class="el-upload__tip" slot="tip">只支持导入excel文件！</div>
    </el-upload>

    <a target="_blank" href="/static/dyqr_import.xls">下载模板</a>
  </el-dialog>



</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        url: '',
        num: 0,
        successNum: 0,
        failDetail: [],
        fileList: []
      }
    },
    methods: {
      init (id) {
        this.url = this.$http.adornUrl(`/bdc/bdcorganinfo/import?token=${this.$cookie.get('token')}`)
        this.visible = true
      },
      // 上传之前
      beforeUploadHandle (file) {

      },
      // 上传成功
      successHandle (response, file) {

        if (response && response.code === 0) {
            if (response.failDetail == 0){
                this.$message({
                  message: response.message,
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                });
            }else{
                var detail = "";
                for (var i in response.failDetail){
                    detail += response.failDetail[i] ;
                }
                this.$message.error(detail);
                this.$refs.upload.clearFiles()
            }
            
        } else {
          this.$message.error(response.msg)
          this.$refs.upload.clearFiles()
        }
      },
      // 弹窗关闭时
      closeHandle () {

        this.$emit('refreshDataList')
      }
    }
  }
</script>
